/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vendingmachine;

/**
 *
 * Nama File    : CoinValidator.Java
 * Deskripsi    : deskripsi dan implementasi kelas Coin yang merupakan anak dari Object
 * Nama Pembuat : Muhammad Ghufron Mahfudhi (23512066) dan Jonathan Ery Pradana (23512038)
 * Hari/Tanggal : Senin / 26 November 2012
 */
public class CoinValidator {
    //referensi koin
    private static final Coin Nickel = new Coin(21.21, 5.0, 1.95, 0, 5);
    private static final Coin Dime = new Coin(17.91, 2.68, 1.35, 118, 10);
    private static final Coin Quarter = new Coin(24.26, 5.67, 1.75, 119, 25);
    
    //atribut
    private Object obj;    //objek yang akan dicek
    private Coin resultCoin;
    private Slug resultSlug;
    private boolean coin;
    
    //method
    
    //ctor
    public CoinValidator(){
        this.obj = new Object();
        this.resultCoin = null;
        this.resultSlug = null;
        this.coin = false;
    }
    
    //ctor berparameter object yang sudah dinyatakan valid sebuah koin
    public CoinValidator(Object o){
        this.obj = new Object(o);
        if(obj.equals(Nickel) || obj.equals(Dime) || obj.equals(Quarter)){
            this.resultSlug = null;
            this.coin = true;
            if(obj.equals(Nickel)){            //cek apakah Nickel
                this.resultCoin = new Coin(o, 5);
            }else if(obj.equals(Dime)){        //cek apakah Dime
                this.resultCoin = new Coin(o, 10);
            }else if(obj.equals(Quarter)){     //cek apakah Quarter
                this.resultCoin = new Coin(o, 25);
            }
        } else{
            this.resultSlug = new Slug(o);
            this.coin = false;
            this.resultCoin = null;
        }
    }
    
    //getter
    public Object getObj() {
        return obj;
    }

    public Coin getResultCoin() {
        return resultCoin;
    }

    public Slug getResultSlug() {
        return resultSlug;
    }

    public boolean isCoin() {
        return coin;
    }

    public static Coin getNickel() {
        return Nickel;
    }

    public static Coin getDime() {
        return Dime;
    }

    public static Coin getQuarter() {
        return Quarter;
    }
    
    //setter
    public void setObj(Object obj) {
        this.obj = obj;
    }

    public void setResultCoin(Coin resultCoin) {
        this.resultCoin = resultCoin;
    }

    public void setResultSlug(Slug resultSlug) {
        this.resultSlug = resultSlug;
    }

    public void setCoin(boolean coin) {
        this.coin = coin;
    }
}
